import { getAllRoomType } from '@/api/api'
export default {
  namespaced:true,
  state: {
    roomTypes: undefined, // 房型数据
  },
  getters: {
    // getRoomTypes(state) {
    //   return state.roomTypes ? state.roomTypes.map(item => item.title) : []
    // },
  },
  mutations: {
    setRoomTypes(state, data) {
      state.roomTypes = data;
    },
  },
  actions: {
    //更新房型数据
    async updateRoomType({ commit }) {
      return Promise.resolve( getAllRoomType().then(response => {
        for(let obj of response.data) {
          obj['isEdit'] = obj['isEdit'] === undefined ? false : obj['isEdit']
          obj['imgUrl'] = obj['imgUrl'] === undefined ? require("@/assets/images/单人大床房.webp") : obj['imgUrl']
        }
        commit('setRoomTypes', response.data);
      }).catch(error => console.log('房型数据请求失败')))
    },
  }
}